// parking_ui.c
#include "parking_ui.h"
#include "parking_common.h"
#include "lv_font_source_han_sans_bold.h"
#include <stdio.h>
#include <string.h>
#include <pthread.h>

// 定义颜色主题
#define COLOR_PRIMARY lv_palette_main(LV_PALETTE_BLUE)
#define COLOR_SECONDARY lv_palette_main(LV_PALETTE_PURPLE)
#define COLOR_SUCCESS lv_palette_main(LV_PALETTE_GREEN)
#define COLOR_WARNING lv_palette_main(LV_PALETTE_ORANGE)
#define COLOR_DANGER lv_palette_main(LV_PALETTE_RED)
#define COLOR_BG lv_color_hex(0xF5F5F5)
#define COLOR_CARD_BG lv_color_white()

// 全局样式
static lv_style_t style_card;
static lv_style_t style_title;
static lv_style_t style_value;
static lv_style_t style_label;

// 全局UI对象指针
static lv_obj_t *g_total_spaces_label = NULL;
static lv_obj_t *g_available_spaces_label = NULL;
static lv_obj_t *g_vehicles_in_label = NULL;
static lv_obj_t *g_vehicles_out_label = NULL;
static lv_obj_t *g_temperature_label = NULL;
static lv_obj_t *g_humidity_label = NULL;
static lv_obj_t *g_floor_b1_bar = NULL;
static lv_obj_t *g_floor_b2_bar = NULL;
static lv_obj_t *g_floor_b3_bar = NULL;

// 圆弧图标签指针
static lv_obj_t *g_duration_labels[4] = {NULL}; // 停车时长分布标签
static lv_obj_t *g_vehicle_labels[3] = {NULL};  // 车辆类型分布标签

// 数据管理
static parking_data_t g_current_data;
static pthread_mutex_t g_data_mutex = PTHREAD_MUTEX_INITIALIZER;
static ui_update_callback_t g_ui_update_callback = NULL;

// 初始化样式
void ui_init_styles(void) {
    printf("Initializing UI styles...\n");
    
    // 卡片样式
    lv_style_init(&style_card);
    lv_style_set_radius(&style_card, 10);
    lv_style_set_bg_opa(&style_card, LV_OPA_COVER);
    lv_style_set_bg_color(&style_card, COLOR_CARD_BG);
    lv_style_set_shadow_width(&style_card, 10);
    lv_style_set_shadow_color(&style_card, lv_color_hex(0xCCCCCC));
    lv_style_set_shadow_ofs_y(&style_card, 5);
    lv_style_set_pad_all(&style_card, 10);

    // 标题样式
    lv_style_init(&style_title);
    lv_style_set_text_font(&style_title, &chinese_ziku);
    lv_style_set_text_color(&style_title, lv_color_black());

    // 数值样式
    lv_style_init(&style_value);
    lv_style_set_text_font(&style_value, &chinese_ziku);
    lv_style_set_text_color(&style_value, COLOR_PRIMARY);

    // 标签样式
    lv_style_init(&style_label);
    lv_style_set_text_font(&style_label, &chinese_ziku);
    lv_style_set_text_color(&style_label, lv_color_hex(0x666666));
    
    printf("UI styles initialized\n");
}

// 创建统计项
static void ui_create_stat_item(lv_obj_t *parent, const char *label, const char *value, 
                               int label_x, int y, int value_x) {
    // 创建标签
    lv_obj_t *label_obj = lv_label_create(parent);
    lv_label_set_text(label_obj, label);
    lv_obj_add_style(label_obj, &style_label, 0);
    lv_obj_set_pos(label_obj, label_x, y);

    // 创建数值
    lv_obj_t *value_obj = lv_label_create(parent);
    lv_label_set_text(value_obj, value);
    lv_obj_add_style(value_obj, &style_value, 0);
    lv_obj_set_pos(value_obj, value_x, y);

    // 保存关键标签的指针用于实时更新
    if (strcmp(label, "总车位数") == 0) {
        g_total_spaces_label = value_obj;
    } else if (strcmp(label, "当前空余车位") == 0) {
        g_available_spaces_label = value_obj;
    } else if (strcmp(label, "今日车辆进场") == 0) {
        g_vehicles_in_label = value_obj;
    } else if (strcmp(label, "今日车辆出场") == 0) {
        g_vehicles_out_label = value_obj;
    } else if (strcmp(label, "温度") == 0) {
        g_temperature_label = value_obj;
    } else if (strcmp(label, "湿度") == 0) {
        g_humidity_label = value_obj;
    }
}

// 创建楼层进度条
static void ui_create_floor_progress(lv_obj_t *parent, const char *label, int percent, 
                                    int y, int floor_index) {
    int x = 5;

    // 创建标签
    lv_obj_t *label_obj = lv_label_create(parent);
    lv_label_set_text(label_obj, label);
    lv_obj_add_style(label_obj, &style_label, 0);
    lv_obj_set_pos(label_obj, x, y);

    // 创建百分比标签
    lv_obj_t *percent_label = lv_label_create(parent);
    char percent_str[10];
    snprintf(percent_str, sizeof(percent_str), "%d%%", percent);
    lv_label_set_text(percent_label, percent_str);
    lv_obj_add_style(percent_label, &style_value, 0);
    lv_obj_set_pos(percent_label, x + 170, y);

    // 创建进度条
    lv_obj_t *bar = lv_bar_create(parent);
    lv_obj_set_size(bar, 220, 8);
    lv_obj_set_pos(bar, x, y + 25);
    lv_bar_set_value(bar, percent, LV_ANIM_ON);

    // 设置进度条颜色
    lv_obj_set_style_bg_color(bar, lv_color_hex(0xE0E0E0), LV_PART_MAIN);
    lv_obj_set_style_bg_color(bar, COLOR_PRIMARY, LV_PART_INDICATOR);

    // 保存进度条指针
    switch (floor_index) {
        case 0: g_floor_b1_bar = bar; break;
        case 1: g_floor_b2_bar = bar; break;
        case 2: g_floor_b3_bar = bar; break;
    }
}

// 创建多段环形图
static lv_obj_t *ui_create_multi_arc_chart(lv_obj_t *parent, int *values, const char **labels, 
                                          lv_color_t *colors, int count, const char *title, 
                                          int x, int y, int size, int chart_type) {
    lv_obj_t *cont = lv_obj_create(parent);
    lv_obj_remove_style_all(cont);
    lv_obj_set_size(cont, size + 150, size + 40);
    lv_obj_set_pos(cont, x, y);

    int total = 0;
    for (int i = 0; i < count; i++) {
        total += values[i];
    }

    // 创建图例（左侧）
    lv_obj_t *legend_cont = lv_obj_create(cont);
    lv_obj_remove_style_all(legend_cont);
    lv_obj_set_size(legend_cont, 130, count * 28);
    lv_obj_align(legend_cont, LV_ALIGN_LEFT_MID, 0, 10);

    for (int i = 0; i < count; i++) {
        lv_obj_t *legend_item = lv_obj_create(legend_cont);
        lv_obj_remove_style_all(legend_item);
        lv_obj_set_size(legend_item, 130, 23);
        lv_obj_set_pos(legend_item, 0, i * 25);

        // 颜色标记
        lv_obj_t *color_indicator = lv_obj_create(legend_item);
        lv_obj_set_size(color_indicator, 10, 10);
        lv_obj_set_style_bg_color(color_indicator, colors[i], 0);
        lv_obj_set_style_radius(color_indicator, 2, 0);
        lv_obj_align(color_indicator, LV_ALIGN_LEFT_MID, 0, 5);

        // 标签和百分比
        lv_obj_t *legend_label = lv_label_create(legend_item);
        char legend_text[20];
        int percentage = (total > 0) ? (values[i] * 100) / total : 0;
        snprintf(legend_text, sizeof(legend_text), "%d%%", percentage);
        lv_label_set_text(legend_label, legend_text);
        lv_obj_set_style_text_font(legend_label, &chinese_ziku, 0);
        lv_obj_set_style_text_color(legend_label, colors[i], 0);
        lv_obj_align(legend_label, LV_ALIGN_RIGHT_MID, 0, 4);

        // 保存标签指针用于更新
        if (chart_type == 0) { // 停车时长分布
            if (i < 4) g_duration_labels[i] = legend_label;
        } else if (chart_type == 1) { // 车辆类型分布
            if (i < 3) g_vehicle_labels[i] = legend_label;
        }

        // 标签名称
        lv_obj_t *name_label = lv_label_create(legend_item);
        lv_label_set_text(name_label, labels[i]);
        lv_obj_set_style_text_font(name_label, &chinese_ziku, 0);
        lv_obj_set_style_text_color(name_label, lv_color_hex(0x666666), 0);
        lv_obj_align_to(name_label, color_indicator, LV_ALIGN_OUT_RIGHT_MID, 3, -3);
    }

    // 创建环形图（右侧）
    int start_angle = 0;
    for (int i = 0; i < count; i++) {
        int angle = (values[i] * 360) / total;

        lv_obj_t *arc = lv_arc_create(cont);
        lv_obj_set_size(arc, size, size);
        lv_obj_align(arc, LV_ALIGN_RIGHT_MID, 0, 0);
        lv_arc_set_rotation(arc, start_angle);
        lv_arc_set_bg_angles(arc, 0, angle);
        lv_arc_set_value(arc, 100);

        // 设置样式
        lv_obj_set_style_arc_width(arc, 12, LV_PART_MAIN);
        lv_obj_set_style_arc_color(arc, colors[i], LV_PART_MAIN);
        lv_obj_set_style_arc_width(arc, 12, LV_PART_INDICATOR);
        lv_obj_set_style_arc_color(arc, colors[i], LV_PART_INDICATOR);
        lv_obj_remove_style(arc, NULL, LV_PART_KNOB);

        start_angle += angle;
    }

    return cont;
}

// 创建总览面板
static void ui_create_overview_panel(lv_obj_t *parent) {
    // 创建总览容器
    lv_obj_t *cont = lv_obj_create(parent);
    lv_obj_set_size(cont, 250, 460);
    lv_obj_set_pos(cont, 10, 10);
    lv_obj_add_style(cont, &style_card, 0);

    // 标题
    lv_obj_t *title = lv_label_create(cont);
    lv_label_set_text(title, "停车场总览");
    lv_obj_add_style(title, &style_title, 0);
    lv_obj_set_pos(title, 70, 15);

    // 使用实时数据创建统计项
    char total_str[32], available_str[32], in_str[32], out_str[32];
    char temp_str[32], humidity_str[32];

    data_get_current(&g_current_data);
    
    snprintf(total_str, sizeof(total_str), "%d", g_current_data.total_spaces);
    snprintf(available_str, sizeof(available_str), "%d", g_current_data.available_spaces);
    snprintf(in_str, sizeof(in_str), "%d", g_current_data.vehicles_in);
    snprintf(out_str, sizeof(out_str), "%d", g_current_data.vehicles_out);
    snprintf(temp_str, sizeof(temp_str), "%d", g_current_data.temperature);
    snprintf(humidity_str, sizeof(humidity_str), "%d%%", g_current_data.humidity);

    ui_create_stat_item(cont, "总车位数", total_str, 20, 50, 170);
    ui_create_stat_item(cont, "当前空余车位", available_str, 20, 90, 170);
    ui_create_stat_item(cont, "今日车辆进场", in_str, 20, 130, 170);
    ui_create_stat_item(cont, "今日车辆出场", out_str, 20, 170, 170);
    ui_create_stat_item(cont, "高峰时段", "08:00-10:00", 20, 210, 108);

    // 创建楼层进度条
    ui_create_floor_progress(cont, "地下1层 200个", g_current_data.floor_b1_utilization, 250, 0);
    ui_create_floor_progress(cont, "地下2层 150个", g_current_data.floor_b2_utilization, 300, 1);
    ui_create_floor_progress(cont, "地下3层 150个", g_current_data.floor_b3_utilization, 350, 2);

    // 添加环境数据显示
    ui_create_stat_item(cont, "温度", temp_str, 10, 390, 70);
    ui_create_stat_item(cont, "湿度", humidity_str, 120, 390, 175);
}

// 创建客户行为分析面板
static void ui_create_customer_behavior_panel(lv_obj_t *parent) {
    lv_obj_t *cont = lv_obj_create(parent);
    lv_obj_set_size(cont, 250, 220);
    lv_obj_set_pos(cont, 270, 10);
    lv_obj_add_style(cont, &style_card, 0);

    // 标题
    lv_obj_t *title = lv_label_create(cont);
    lv_label_set_text(title, "客户行为分析");
    lv_obj_add_style(title, &style_title, 0);
    lv_obj_set_pos(title, 55, 0);

    // 统计数据
    char avg_time[32], avg_consumption[32], member_ratio_str[32];
    snprintf(avg_time, sizeof(avg_time), "%.1f小时", g_current_data.avg_parking_time_x100 / 100.0);
    snprintf(avg_consumption, sizeof(avg_consumption), "$%.2f", g_current_data.avg_consumption_x100 / 100.0);
    snprintf(member_ratio_str, sizeof(member_ratio_str), "%d%%", g_current_data.member_ratio);

    ui_create_stat_item(cont, "平均停车时长", avg_time, 0, 25, 140);
    ui_create_stat_item(cont, "平均消费金额", avg_consumption, 0, 50, 140);
    ui_create_stat_item(cont, "会员占比", member_ratio_str, 0, 75, 100);

    // 创建环形图显示停车时长分布
    int duration_values[] = {
        g_current_data.parking_time_less_1h,
        g_current_data.parking_time_1_2h,
        g_current_data.parking_time_2_4h,
        g_current_data.parking_time_more_4h
    };
    
    const char *duration_labels[] = {"<1h", "1-2h", "2-4h", ">4h"};
    lv_color_t duration_colors[] = {COLOR_PRIMARY, COLOR_SUCCESS, COLOR_WARNING, COLOR_SECONDARY};

    ui_create_multi_arc_chart(cont, duration_values, duration_labels, duration_colors, 4, 
                             "停车时长分布", 0, 90, 65, 0);
}

// 创建高峰时段面板
static void ui_create_peak_hours_panel(lv_obj_t *parent) {
    lv_obj_t *cont = lv_obj_create(parent);
    lv_obj_set_size(cont, 250, 220);
    lv_obj_set_pos(cont, 530, 10);
    lv_obj_add_style(cont, &style_card, 0);

    // 标题
    lv_obj_t *title = lv_label_create(cont);
    lv_label_set_text(title, "高峰时段与流量预测");
    lv_obj_add_style(title, &style_title, 0);
    lv_obj_set_pos(title, 25, 0);

    // 这里可以添加柱状图代码，由于篇幅限制暂时简化
    lv_obj_t *info_label = lv_label_create(cont);
    lv_label_set_text(info_label, "高峰时段: 08:00-10:00\n16:00-18:00");
    lv_obj_add_style(info_label, &style_label, 0);
    lv_obj_set_pos(info_label, 20, 40);
}

// 创建车牌识别面板
static void ui_create_license_plate_panel(lv_obj_t *parent) {
    lv_obj_t *cont = lv_obj_create(parent);
    lv_obj_set_size(cont, 250, 220);
    lv_obj_set_pos(cont, 270, 240);
    lv_obj_add_style(cont, &style_card, 0);

    // 标题
    lv_obj_t *title = lv_label_create(cont);
    lv_label_set_text(title, "车牌识别与车辆信息");
    lv_obj_add_style(title, &style_title, 0);
    lv_obj_set_pos(title, 25, 0);

    // 统计数据
    char recognized_str[32], unrecognized_str[32];
    snprintf(recognized_str, sizeof(recognized_str), "%d", g_current_data.recognized_vehicles);
    snprintf(unrecognized_str, sizeof(unrecognized_str), "%.1f%%", g_current_data.unrecognized_rate_x100 / 100.0);

    ui_create_stat_item(cont, "今日识别车辆", recognized_str, 0, 25, 140);
    ui_create_stat_item(cont, "未识别率", unrecognized_str, 0, 50, 140);

    // 创建环形图显示车辆类型分布
    int vehicle_values[] = {
        g_current_data.vehicle_type_truck,
        g_current_data.vehicle_type_suv,
        g_current_data.vehicle_type_car
    };
    
    const char *vehicle_labels[] = {"货车", "SUV", "轿车"};
    lv_color_t vehicle_colors[] = {COLOR_PRIMARY, COLOR_SUCCESS, COLOR_WARNING};

    ui_create_multi_arc_chart(cont, vehicle_values, vehicle_labels, vehicle_colors, 3, 
                             NULL, 0, 60, 65, 1);
}

// 创建客户反馈面板
static void ui_create_feedback_panel(lv_obj_t *parent) {
    lv_obj_t *cont = lv_obj_create(parent);
    lv_obj_set_size(cont, 250, 220);
    lv_obj_set_pos(cont, 530, 240);
    lv_obj_add_style(cont, &style_card, 0);

    // 标题
    lv_obj_t *title = lv_label_create(cont);
    lv_label_set_text(title, "客户反应与满意度");
    lv_obj_add_style(title, &style_title, 0);
    lv_obj_set_pos(title, 35, 0);

    // 反馈信息
    char waiting_time_str[32], facility_score_str[32], service_score_str[32], satisfaction_str[32];
    snprintf(waiting_time_str, sizeof(waiting_time_str), "%.1f分钟", g_current_data.avg_waiting_time_x100 / 100.0);
    snprintf(facility_score_str, sizeof(facility_score_str), "%.1f/5", g_current_data.facility_score_x100 / 100.0);
    snprintf(service_score_str, sizeof(service_score_str), "%.1f/5", g_current_data.service_score_x100 / 100.0);
    snprintf(satisfaction_str, sizeof(satisfaction_str), "%d/100", g_current_data.satisfaction_score);

    ui_create_stat_item(cont, "平均等待时间", waiting_time_str, 0, 35, 140);
    ui_create_stat_item(cont, "设施评分", facility_score_str, 0, 60, 140);
    ui_create_stat_item(cont, "服务评分", service_score_str, 0, 85, 140);
    ui_create_stat_item(cont, "总体满意度", satisfaction_str, 0, 110, 140);
}

// UI更新函数
void ui_update_display(parking_data_t *data) {
    printf("Updating UI display...\n");
    
    // 基础停车数据
    if (g_total_spaces_label) {
        char buffer[32];
        snprintf(buffer, sizeof(buffer), "%d", data->total_spaces);
        lv_label_set_text(g_total_spaces_label, buffer);
    }

    if (g_available_spaces_label) {
        char buffer[32];
        snprintf(buffer, sizeof(buffer), "%d", data->available_spaces);
        lv_label_set_text(g_available_spaces_label, buffer);
    }

    if (g_vehicles_in_label) {
        char buffer[32];
        snprintf(buffer, sizeof(buffer), "%d", data->vehicles_in);
        lv_label_set_text(g_vehicles_in_label, buffer);
    }

    if (g_vehicles_out_label) {
        char buffer[32];
        snprintf(buffer, sizeof(buffer), "%d", data->vehicles_out);
        lv_label_set_text(g_vehicles_out_label, buffer);
    }

    // 环境数据
    if (g_temperature_label) {
        char buffer[32];
        snprintf(buffer, sizeof(buffer), "%d", data->temperature);
        lv_label_set_text(g_temperature_label, buffer);
    }

    if (g_humidity_label) {
        char buffer[32];
        snprintf(buffer, sizeof(buffer), "%d%%", data->humidity);
        lv_label_set_text(g_humidity_label, buffer);
    }

    // 更新进度条
    if (g_floor_b1_bar) {
        lv_bar_set_value(g_floor_b1_bar, data->floor_b1_utilization, LV_ANIM_ON);
    }

    if (g_floor_b2_bar) {
        lv_bar_set_value(g_floor_b2_bar, data->floor_b2_utilization, LV_ANIM_ON);
    }

    if (g_floor_b3_bar) {
        lv_bar_set_value(g_floor_b3_bar, data->floor_b3_utilization, LV_ANIM_ON);
    }

    // 更新停车时长分布标签
    int duration_total = data->parking_time_less_1h + data->parking_time_1_2h + 
                        data->parking_time_2_4h + data->parking_time_more_4h;

    if (duration_total > 0) {
        int duration_values[] = {
            data->parking_time_less_1h,
            data->parking_time_1_2h,
            data->parking_time_2_4h,
            data->parking_time_more_4h
        };

        for (int i = 0; i < 4; i++) {
            if (g_duration_labels[i]) {
                char percent_text[20];
                int percentage = (duration_values[i] * 100) / duration_total;
                snprintf(percent_text, sizeof(percent_text), "%d%%", percentage);
                lv_label_set_text(g_duration_labels[i], percent_text);
            }
        }
    }

    // 更新车辆类型分布标签
    int vehicle_total = data->vehicle_type_truck + data->vehicle_type_suv + data->vehicle_type_car;

    if (vehicle_total > 0) {
        int vehicle_values[] = {
            data->vehicle_type_truck,
            data->vehicle_type_suv,
            data->vehicle_type_car
        };

        for (int i = 0; i < 3; i++) {
            if (g_vehicle_labels[i]) {
                char percent_text[20];
                int percentage = (vehicle_values[i] * 100) / vehicle_total;
                snprintf(percent_text, sizeof(percent_text), "%d%%", percentage);
                lv_label_set_text(g_vehicle_labels[i], percent_text);
            }
        }
    }
    
    printf("UI display updated\n");
}

// 创建主界面
void ui_create_dashboard(void) {
    printf("Creating parking dashboard...\n");
    
    // 初始化样式
    ui_init_styles();

    // 设置屏幕背景色
    lv_obj_set_style_bg_color(lv_scr_act(), COLOR_BG, 0);

    // 创建各个面板
    ui_create_overview_panel(lv_scr_act());
    ui_create_customer_behavior_panel(lv_scr_act());
    ui_create_peak_hours_panel(lv_scr_act());
    ui_create_license_plate_panel(lv_scr_act());
    ui_create_feedback_panel(lv_scr_act());

    // 注册UI更新回调
    ui_register_update_callback(ui_update_display);
    
    printf("Parking dashboard created successfully\n");
}

// 注册UI更新回调
void ui_register_update_callback(ui_update_callback_t callback) {
    g_ui_update_callback = callback;
}

// 数据访问函数
void data_get_current(parking_data_t *dest) {
    pthread_mutex_lock(&g_data_mutex);
    memcpy(dest, &g_current_data, sizeof(parking_data_t));
    pthread_mutex_unlock(&g_data_mutex);
}

void data_update_current(parking_data_t *new_data) {
    pthread_mutex_lock(&g_data_mutex);
    memcpy(&g_current_data, new_data, sizeof(parking_data_t));
    pthread_mutex_unlock(&g_data_mutex);

    // 通知UI更新
    if (g_ui_update_callback) {
        g_ui_update_callback(new_data);
    }
}

// 数据模拟函数
void data_generate_simulated(parking_data_t *data) {
    static int counter = 0;

    // 使用当前数据作为基础，添加随机波动
    parking_data_t current_data;
    data_get_current(&current_data);

    // 基础停车数据波动
    data->total_spaces = current_data.total_spaces;
    
    int change = (rand() % 11) - 5; // -5 到 +5 的变化
    data->available_spaces = current_data.available_spaces + change;
    
    // 边界检查
    if (data->available_spaces < 0) data->available_spaces = 0;
    if (data->available_spaces > data->total_spaces) 
        data->available_spaces = data->total_spaces;

    data->occupied_spaces = data->total_spaces - data->available_spaces;
    data->utilization_rate = (data->occupied_spaces * 100) / data->total_spaces;
    
    // 环境数据波动
    data->temperature = current_data.temperature + (rand() % 5 - 2);
    if (data->temperature < 15) data->temperature = 15;
    if (data->temperature > 35) data->temperature = 35;
    
    data->humidity = current_data.humidity + (rand() % 11 - 5);
    if (data->humidity < 30) data->humidity = 30;
    if (data->humidity > 80) data->humidity = 80;
    
    // 时间戳
    data->timestamp = (int64_t)time(NULL);
    
    // 其他数据可以类似处理，这里省略详细实现
    
    counter++;
}

// 数据初始化
void data_initialize_defaults(void) {
    pthread_mutex_lock(&g_data_mutex);
    
    // 设置默认数据
    memset(&g_current_data, 0, sizeof(parking_data_t));
    
    g_current_data.total_spaces = 500;
    g_current_data.available_spaces = 325;
    g_current_data.occupied_spaces = 175;
    g_current_data.utilization_rate = 35;
    
    g_current_data.temperature = 25;
    g_current_data.humidity = 60;
    g_current_data.light_level = 450;
    g_current_data.air_quality = 75;
    
    g_current_data.vehicles_in = 1245;
    g_current_data.vehicles_out = 1198;
    g_current_data.vehicles_current = 47;
    
    g_current_data.timestamp = time(NULL);
    g_current_data.peak_hour_flag = 0;
    
    g_current_data.floor_b1_total = 200;
    g_current_data.floor_b1_available = 50;
    g_current_data.floor_b1_utilization = 75;
    
    g_current_data.floor_b2_total = 150;
    g_current_data.floor_b2_available = 60;
    g_current_data.floor_b2_utilization = 60;
    
    g_current_data.floor_b3_total = 150;
    g_current_data.floor_b3_available = 22;
    g_current_data.floor_b3_utilization = 85;
    
    g_current_data.avg_parking_time_x100 = 250;
    g_current_data.avg_consumption_x100 = 4560;
    g_current_data.member_ratio = 68;
    
    g_current_data.parking_time_less_1h = 35;
    g_current_data.parking_time_1_2h = 20;
    g_current_data.parking_time_2_4h = 20;
    g_current_data.parking_time_more_4h = 25;
    
    g_current_data.recognized_vehicles = 1245;
    g_current_data.unrecognized_rate_x100 = 230;
    g_current_data.vehicle_type_truck = 560;
    g_current_data.vehicle_type_suv = 374;
    g_current_data.vehicle_type_car = 311;
    
    strncpy(g_current_data.common_feedback, "车位充足", sizeof(g_current_data.common_feedback)-1);
    g_current_data.common_feedback[sizeof(g_current_data.common_feedback)-1] = '\0';
    
    g_current_data.avg_waiting_time_x100 = 850;
    g_current_data.facility_score_x100 = 450;
    g_current_data.service_score_x100 = 430;
    g_current_data.satisfaction_score = 90;
    
    g_current_data.hour_6_count = 20;
    g_current_data.hour_8_count = 120;
    g_current_data.hour_10_count = 80;
    g_current_data.hour_12_count = 40;
    g_current_data.hour_14_count = 60;
    g_current_data.hour_16_count = 100;
    g_current_data.hour_18_count = 130;
    g_current_data.hour_20_count = 70;
    
    pthread_mutex_unlock(&g_data_mutex);
    
    printf("Default data initialized\n");
}